//
//  MAlertView.m
//  IpadVideo
//
//  Created by 红沙尘 on 14-7-1.
//  Copyright (c) 2014年 红沙尘. All rights reserved.
//

#import "MAlertView.h"
#import "Mtool.h"
@implementation MAlertView
@synthesize delegate;


- (void)awakeFromNib
{
    self.layer.cornerRadius = 5.0f;
    self.layer.masksToBounds = YES;
    
    label.font = [UIFont systemFontOfSize:15.0f];
    
    CGRect frame = self.frame;
    frame.origin.y = (768-50)/2;
    frame.origin.x = (1024-200)/2;
    self.frame = frame;
}

- (void)showWithTitle:(NSString *)title inView:(UIView *)view
{
    [view addSubview:self];
    
    label.text = title;
    CGFloat h = [MTool sizeWithText:label.text
                               font:label.font
                  constrainedToSize:CGSizeMake(200, 500)].height + 10;
    h = MAX(h, 40);
    
    CGRect frame = self.frame;
    frame.size.height = h;
    frame.origin.y = (view.frame.size.height-h)/2-h;
    frame.origin.x = (view.frame.size.width-200)/2;
    self.frame = frame;
    
    CGRect lFrame = label.frame;
    lFrame.size.height = h;
    label.frame = lFrame;
    
    [self performSelector:@selector(remove) withObject:nil afterDelay:1.0];
}

- (void)remove
{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0.5;
    }completion:^(BOOL finished){
        
        if ([delegate respondsToSelector:@selector(malertviewDidMiss)])
        {
            [delegate malertviewDidMiss];
        }
        [self removeFromSuperview];
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
